package cn.liwq.demo.config;

import cn.liwq.demo.annotation.ScaleFormatter;
import cn.liwq.demo.serializer.ScaleSerializer;
import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;

/**
 * @author lweiqiang
 * @date 2023/2/13
 */
public class ScaleFormatterAnnotationIntrospector extends JacksonAnnotationIntrospector {
  @Override
  public Object findSerializer(Annotated annotated) {
    ScaleFormatter jsonScaleFormatter = annotated.getAnnotation(ScaleFormatter.class);
    if (jsonScaleFormatter != null) {
      return new ScaleSerializer(jsonScaleFormatter.scale(), jsonScaleFormatter.roundingMode());
    }
    return super.findSerializer(annotated);
  }
}
